package cn.elves.model.strategy.controller;

import cn.elves.model.entity.dto.response.ResponseDTO;
import cn.elves.model.strategy.entity.dto.StrategyDTO;
import cn.elves.model.strategy.entity.po.Strategy;
import cn.elves.model.strategy.service.StrategyService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("drawing")
public class StrategyController {

    @Resource
    private StrategyService strategyService;

    @GetMapping("/strategy/page/{pageSize}/{pageNum}")
    public ResponseDTO<Page<Strategy>> strategyPage(@PathVariable("pageSize") Integer pageSize, @PathVariable("pageNum") Integer pageNum) {
        return ResponseDTO.success(strategyService.page(new Page<>(pageSize, pageNum)));
    }

    @GetMapping("/strategy/{id}")
    public ResponseDTO<Strategy> selectStrategy(@PathVariable("id") Long id) {
        return ResponseDTO.success(strategyService.getById(id));
    }

    @PostMapping("/strategy")
    public ResponseDTO<Strategy> saveStrategy(Strategy strategy) {
        strategyService.save(strategy);
        return ResponseDTO.success();
    }

    @PutMapping("/strategy")
    public ResponseDTO<Strategy> updateStrategy(StrategyDTO strategy) {
        strategyService.updateStrategy(strategy);
        return ResponseDTO.success();
    }
}
